#include<iostream>
#include <winsock2.h>
#include<vector>
#include"databaseOp.h"
#include"startapp.h"

using namespace std;
CDrive cDrive;

void addMember(vector<string> &splOrder)      //  命令行调用添加会员
{
	if (splOrder.size() != 4){
		cout << "FALIED. WRONG ORDER!" << endl;
		return;
	}
	else{
		if (cDrive.insertToMember(splOrder[1], splOrder[2], splOrder[3]) == 0){
			cout << "OK. " << splOrder[1] << "'s member id is " << cDrive.getMemberID(splOrder[1]) << "." << endl;
		return;
		}
	}
}

void addCard(vector<string> &splOrder)    //  命令行调用添加 卡
{
	if (splOrder.size() == 3 && splOrder[2] == "年卡"){
		if (cDrive.insertToCardOfYear(splOrder[1]) == 0)
			cout << "OK. A new 年卡 add to " << splOrder[1] << "." << endl;
		return;
	}
	if (splOrder.size() == 4 && splOrder[2] == "次卡"){
		if (cDrive.insertToCardOfTime(splOrder[1], splOrder[3]) == 0)
			cout << "OK. A new 次卡 add to " << splOrder[1] << "." << endl;
		return;
	}
	else{
		cout << "FALIED. WRONG ORDER!" << endl;
	}
}

void addCourse(vector<string> &splOrder)   //  命令行调用添加 课程
{
	if (splOrder.size() == 2){
		if (cDrive.insertToCourse(splOrder[1]) == 0)
			cout << "OK. 课程 " << splOrder[1] << " 添加成功." << endl;
		return;
	}
	else{
		cout << "FALIED. WRONG ORDER!" << endl;
	}
}

void addCoach(vector<string> &splOrder)    //  命令行调用添加 教练
{
	if (splOrder.size() != 5){
		cout << "FALIED. WRONG ORDER!" << endl;
		return;
	}
	else{
		if (cDrive.insertToCoach(splOrder[1], splOrder[2], splOrder[3], splOrder[4]) == 0){
			cout << "OK. 教练 " << splOrder[1] << " 添加成功. " << endl;
		}
	}
}

void schedule(vector<string> &splOrder)   //  命令行调用  排课
{
	if (splOrder.size() != 4){
		cout << "FALIED. WRONG ORDER!" << endl;
		return;
	}
	else{
		if (cDrive.insertToSchedule(splOrder[1], splOrder[2], splOrder[3]) == 0){
			cout << "OK. 排课成功 " << endl;
		}
	}
}

void subscribe(vector<string> &splOrder)     //  命令行调用  预订课程
{
	if (splOrder.size() != 3){
		cout << "FALIED. WRONG ORDER!" << endl;
		return;
	}
	else{
		if (cDrive.insertToCourseOrder(splOrder[1], splOrder[2]) == 0){
			cout << "OK. " << splOrder[1] << "预订成功, 请准时前往剑瑜伽馆上课." << endl;
		}
	}
}

int main()
{
	string order;
	while (true){
		cout << "> iyoga ";
		getline(cin, order);
		if (order == "\0")
			continue;
		vector<string> splOrder = cDrive.splitStr(order, ' ');
		if (splOrder[0] == "add-member"){
			addMember(splOrder);
			continue;
		}
		if (splOrder[0] == "add-card"){
			addCard(splOrder);
			continue;
		}
		if (splOrder[0] == "add-course"){
			addCourse(splOrder);
			continue;
		}
		if (splOrder[0] == "add-coach"){
			addCoach(splOrder);
			continue;
		}
		if (splOrder[0] == "schedule"){
			schedule(splOrder);
			continue;
		}
		if (splOrder[0] == "subscribe"){
			subscribe(splOrder);
			continue;
		}
		else{
			cout << "FALIED. WRONG ORDER!" << endl;
		}
	}
	return 0;
}